home *** CD-ROM | disk | FTP | other *** search
/ Aminet 20 / Aminet 20 (1997)(GTI - Schatztruhe)[!][Aug 1997].iso / Aminet / comm / www / N2v.lha / N2V.c < prev    next >
C/C++ Source or Header  |  1997-05-31  |  2KB  |  101 lines

  1. /* Netscape to Voyager Bookmark file converter */
  2.  
  3. #include <libraries/dosextens.h>
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <string.h>
  7.  
  8. void Copyright(void);
  9.  
  10. /* constants declaration */
  11.  
  12. #define MAXBUF 128
  13. #define MAXINBUF 4097
  14. #define MAXOUTBUF 128
  15.  
  16. /* variables declaration */
  17.  
  18. char filein[MAXBUF], filelow[MAXBUF];
  19. char databuf[MAXINBUF];
  20. char *pointer, *ptr;
  21. FILE *fi, *fl;
  22.  
  23. char *prolog= "<! Voyager - Bookmarks.mcc >\n<!!! This is automatically generated... Do NOT edit !!!>\n<HTML>\n<TITLE>Voyager Bookmarks</TITLE>\n<BODY>\n\n<H1 ALIGN=CENTER>Voyager Bookmarks</H1>\n<HR>\n";
  24. char *postlog= "<BR>\n<HR>\n<a href=\"About:\">Voyager 2.88 (20.05.97)</a>\n</BODY>\n</HTML>";
  25.  
  26.  
  27. main(argc, argv)
  28.  
  29. int argc;
  30. char *argv[];
  31.  
  32. {
  33. int i=1;
  34.     Copyright();
  35.     if(argc==1) {
  36. badusage:    printf("Usage: %s filename [filename]\n",argv[0]);
  37.         exit(1);
  38.     }
  39.  
  40. /* insert options handling here */
  41.  
  42.     if(!(--argc))
  43.         goto badusage;
  44.     strcpy(filein,argv[i]);
  45.     strcpy(filelow,filein);
  46.     strcat(filelow,".html");
  47.     if(--argc)
  48.         strcpy(filelow,argv[++i]);
  49.     if(!(fi=fopen(filein,"r"))) {
  50.         printf("Can't open file %s for input\n",filein);
  51.         exit(1);
  52.     }
  53.     if(!(fl=fopen(filelow,"w"))) {
  54.         printf("Can't open file %s for output\n",filelow);
  55.         fclose(fi);
  56.         exit(1);
  57.     }
  58.     
  59.     fputs(prolog,fl);
  60.     
  61.     while(fgets(databuf,sizeof(databuf),fi)){
  62.         
  63.         pointer=stpblk(databuf);
  64.         if(i=stcsma(pointer,"<DL>*"))
  65.             fputs("<UL>\n",fl);
  66.         if(i=stcsma(pointer,"</DL>*"))
  67.                 fputs("</UL>\n",fl);
  68.         if(i=stcsma(pointer,"<DT>*")) {
  69.             fputs("<LI>",fl);
  70.             pointer+=4;
  71.             pointer=stpblk(pointer);
  72.             if(i=stcsma(pointer,"<H*")) {
  73.                 ptr=strtok(pointer,">");
  74.                 pointer=strtok(NULL,"<");
  75.                 fputs(pointer,fl);
  76.             }
  77.             else if(i=stcsma(pointer,"<A HREF=*")) {
  78.                 ptr=strtok(pointer,"\"");
  79.                 pointer=strtok(NULL,"\"");
  80.                 fputs("<A HREF=\"",fl);
  81.                 fputs(pointer,fl);
  82.                 fputs("\">",fl);
  83.                 pointer=strtok(NULL,">");
  84.                 pointer=strtok(NULL,"\0");
  85.                 fputs(pointer,fl);
  86.             }
  87.         }
  88.         /* DT DL DT /DL */
  89.         
  90.             
  91.         
  92.     }
  93.     fputs(postlog,fl);
  94.     fclose(fi);
  95.     fclose(fl);
  96. }
  97.  
  98. void Copyright(void)
  99. {
  100.     puts("Netscrap to Voyager bookmarks file converter (C)1997 by SRC");
  101. }